package com.kgcx.organization.service;

import com.github.pagehelper.PageHelper;
import com.kgcx.common.bean.RequestData;
import com.kgcx.common.eum.CommonDataEeum;
import com.kgcx.dbutils.utils.PageUtils;
import com.kgcx.organization.domain.DriverCensus;
import com.kgcx.organization.mapper.DriverCensusMapper;
import com.kgcx.organization.rabbitmq.producer.DriverCensusProducer;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Timestamp;
import java.util.List;

/**
 * 驾驶员统计
 *
 * @author qinze
 */
@Service
public class DriverCensusService {

    @Resource
    private DriverCensusMapper driverCensusMapper;
    @Resource
    private DriverCensusProducer driverCensusProducer;

    public void insertDriverCensus(DriverCensus driverCensus) {
        driverCensus.setStatus(CommonDataEeum.DATA_STATE_NORMAL.getCode());
        driverCensus.setCreateTime(new Timestamp(System.currentTimeMillis()));
        driverCensus.setUpdateTime(new Timestamp(System.currentTimeMillis()));
        driverCensusMapper.insertSelective(driverCensus);
        driverCensusProducer.addDriverCensusProducer(driverCensus);
    }

    public List<DriverCensus> selectDriverCensus(RequestData rd) {
        DriverCensus driverCensus = new DriverCensus();
        driverCensus.setKid(rd.getLong("kid"));
        return driverCensusMapper.selectActive(driverCensus);
    }

    /**
     * 监管平台查询驾驶员统计信息
     * @param rd
     * @return
     */
    public List<DriverCensus> queryDriverGensusWithPage(RequestData rd) {
        DriverCensus driverCensus = new DriverCensus();
        driverCensus.setKid(rd.getLong("kid"));
        driverCensus.setLicenseId(rd.getString("licenseId"));
        PageUtils.page(rd);
        PageHelper.orderBy(rd.getOrderBy());
        List<DriverCensus> list = driverCensusMapper.selectActive(driverCensus);
        for (DriverCensus gensus:list){
            driverCensusProducer.addDriverCensusProducer(gensus);
        }
        return list;
    }

}
